<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>Chat</title>
	</head>
    <link rel="stylesheet" href="css/index.css">
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        axios.defaults.baseURL = "http://127.0.0.1:9001"
        // axios.defaults.baseURL = "https://6f909b12.r10.cpolar.top"
    </script>
	<body>
		<div id="app">
		    <chat-views id="chatViews"></chat-views>
            <script>
                /**设置联想的回调方法
                 * @param {string} input 输入
                 */
                chatViews.onInputAssociation = async function(input) {
                    return [input]
                }
                /**设置输入响应的回调方法
                 * @param {string} input 输入
                 * @returns {string} 回复文本
                 */
                chatViews.onMsgResponse = async function(input) {
                    const resp = await axios.post("/api/chat", { 
                        userinput: input,
                    })
                    const { code, data } = resp.data
                    if (code == 200) {
                        return data
                    } else {
                        window.tip({message: "error", type: "error"})
                    }
                }
            </script>
		</div>
	</body>
</html>
<script src="js/index.js"></script>
